const RECommon = {
  // 域名
  domain: () => {
    let pattern = String.raw`^[A-Za-z0-9_\u4e00-\u9fa5]+([.-][A-Za-z0-9_\u4e00-\u9fa5]+)*$`;
    let msg = '域名格式错误';
    return {
      reg: new RegExp(pattern, 'i'),
      msg,
    };
  },
  // url
  url: () => {
    let pattern = String.raw`^[a-zA-z]+://[^s]*$`;
    let msg = 'url格式错误';
    return {
      reg: new RegExp(pattern, 'i'),
      msg,
    };
  },
  // uri
  uri: () => {
    let pattern = String.raw`^(?!.*<[a-zA-Z]+.*[/]?>.*)[\u4e00-\u9fa5\u0020-\u007e\u00b7]*$`;
    let msg = 'uri格式错误';
    return {
      reg: new RegExp(pattern, 'i'),
      msg,
    };
  },
  // ip
  uri: () => {
    let pattern = String.raw`^(\d{1,2}|1\d\d|2[0-4]d|25[0-5]).(\d{1,2}|1\d\d|2[0-4]d|25[0-5]).(\d{1,2}|1\d\d|2[0-4]\d|25[0-5]).(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$`;
    let msg = '错误的ip地址';
    return {
      reg: new RegExp(pattern, ''),
      msg,
    };
  },
  // 网段
  ipSeg: () => {
    let pattern = String.raw`^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5]).(\d{1,2}|1\d\d|2[0-4]\d|25[0-5]).(\d{1,2}|1\d\d|2[0-4]\d|25[0-5]).(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])-(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$`;
    let msg = '错误的ip网段';
    return {
      reg: new RegExp(pattern, ''),
      msg,
    };
  },
  // 端口
  port: () => {
    let pattern = String.raw`^([0-9]|[1-9]\d{1,3}|[1-5]\d{4}|6[0-4]\d{3}|65[0-4]\d{2}|655[0-2]\d|6553[0-5])$`;
    let msg = '端口格式错误';
    return {
      reg: new RegExp(pattern, ''),
      msg,
    };
  },
  // 批量ip
  ips: () => {
    let pattern = String.raw`^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5]).(\d{1,2}|1\d\d|2[0-4]\d|25[0-5]).(\d{1,2}|1\d\d|2[0-4]\d|25[0-5]).(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])(,(\d{1,2}|1\d\d|2[0-4]\d|25[0-5]).(\d{1,2}|1\d\d|2[0-4]\d|25[0-5]).(\d{1,2}|1\d\d|2[0-4]\d|25[0-5]).(\d{1,2}|1\d\d|2[0-4]\d|25[0-5]))*$`;
    let msg = '错误的多ip地址';
    return {
      reg: new RegExp(pattern, ''),
      msg,
    };
  },
  // 掩码
  maskIp: () => {
    let pattern = String.raw`^(254|252|248|240|224|192|128|0).0.0.0|255.(254|252|248|240|224|192|128|0).0.0|255.255.(254|252|248|240|224|192|128|0).0|255.255.255.(254|252|248|240|224|192|128|0)$`;
    let msg = '错误的ip掩码地址';
    return {
      reg: new RegExp(pattern, ''),
      msg,
    };
  },
  // 网关
  gateIp: () => {
    let pattern = String.raw`^[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+.?$`;
    let msg = '错误的ip网关地址';
    return {
      reg: new RegExp(pattern, ''),
      msg,
    };
  },
};

export default RECommon;
